package com.by.toolkit.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Tian Wei
 * @version 1.0
 * @date 2024/3/28 4:27 PM
 */
@Getter
@AllArgsConstructor
public enum ExternalContactEnum {

    ADD_EXTERNAL_CONTACT(ExternalContactEnum.ADD_EXTERNAL_CONTACT_CODE, "add_external_contact", "添加企业客户事件", FlagEnum.YES.getCode()),
    ADD_HALF_EXTERNAL_CONTACT(ExternalContactEnum.ADD_HALF_EXTERNAL_CONTACT_CODE, "add_half_external_contact", "外部联系人免验证添加成员事件", FlagEnum.YES.getCode()),
    DEL_EXTERNAL_CONTACT(ExternalContactEnum.DEL_EXTERNAL_CONTACT_CODE, "del_external_contact", "删除企业客户事件", FlagEnum.YES.getCode()),
    EDIT_EXTERNAL_CONTACT(ExternalContactEnum.EDIT_EXTERNAL_CONTACT_CODE, "edit_external_contact", "编辑企业客户事件", FlagEnum.NO.getCode()),
    DEL_FOLLOW_USER(ExternalContactEnum.DEL_FOLLOW_USER_CODE, "del_follow_user", "删除跟进成员事件", FlagEnum.YES.getCode()),
    TRANSFER_FAIL(ExternalContactEnum.TRANSFER_FAIL_CODE, "transfer_fail", "客户接替失败事件", FlagEnum.NO.getCode()),
    ;

    private final Integer type;

    private final String changeType;

    private final String desc;

    private final Integer processFlag;

    private static final Map<String, Integer> CHANGE_TYPE_MAP;

    private static final Map<String, ExternalContactEnum> CHANGE_TYPE_ENUM_MAP;

    static {
        CHANGE_TYPE_MAP = Stream.of(ExternalContactEnum.values())
                .collect(Collectors.toMap(ExternalContactEnum::getChangeType, ExternalContactEnum::getType));
        CHANGE_TYPE_ENUM_MAP = Stream.of(ExternalContactEnum.values())
                .collect(Collectors.toMap(ExternalContactEnum::getChangeType, Function.identity()));
    }

    public static final int ADD_EXTERNAL_CONTACT_CODE = 1;
    public static final int ADD_HALF_EXTERNAL_CONTACT_CODE = 3;
    public static final int DEL_EXTERNAL_CONTACT_CODE = 4;
    public static final int EDIT_EXTERNAL_CONTACT_CODE = 2;
    public static final int DEL_FOLLOW_USER_CODE = 5;
    public static final int TRANSFER_FAIL_CODE = 6;

    public static Boolean handlerChangeType(String changeType) {
        return CHANGE_TYPE_MAP.containsKey(changeType);
    }

    public static ExternalContactEnum resolveChangeType(String changeType) {
        return CHANGE_TYPE_ENUM_MAP.get(changeType);
    }
}
